<!DOCTYPE HTML>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<title>添加新闻</title>


<link rel="stylesheet" href="/css/bootstrap.min.css">
<script src="/js/jquery.js"></script>
<script src="/js/bootstrap.min.js"></script>
	<script src="/js/laydate.js"></script>
	<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
	<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
<style type="text/css">
#container {
	margin-top: -20px;

	margin-left: 10px;
}
</style>

</head>
<body>
	<div id="container">
		<div class="page-header text-center">
				<h2 style="text-align: left">添加新闻</h2>
		</div>
		<div class="row">
			<div class="col-xs-6 col-sm-4 col-md-offset-4">
<!--				-->
				<form  id="newsForm" class="form-horizontal" method="post" enctype="multipart/form-data" >
					<table class="table table-bordered table-condensed ">
						<thead></thead>
						<tbody>
							<tr class="text-center">
								<td>新闻标题</td>
								<td>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="newsTitle" >
									</div></td>
							</tr>
							<tr class="text-center">
								<td>新闻封面</td>
								<td>
									<div class="col-sm-10">
										<input type="file" class="form-control" id="typePicture" name="newsCover" >
									</div>
								</td>
							</tr>
							<tr class="text-center">
								<td>新闻描述</td>
								<td>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="description" >
									</div></td>
							</tr>
							<tr class="text-center">
								<td>新闻日期</td>
								<td>
									<div class="col-sm-10">
										<input  id="newsDate" type="text" class="form-control" name="newsDate" >
										<script>
											//执行一个laydate实例
											laydate.render({
												elem: '#newsDate', //指定元素
												trigger: 'click'
											});
										</script>
									</div></td>
							</tr>
							<tr class="text-center">
								<td>新闻链接</td>
								<td>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="newsHref" >
									</div></td>
							</tr>
						</tbody>
					</table>
					<div class="row">
						<div class="col-xs-6 col-sm-7">
							<div class="form-group">
								<div class="col-sm-offset-4 col-sm-4">
									<input type="button" class="btn btn-primary" value="确认" onclick="submitForm()" />
								</div>
							</div>
						</div>
<!--						<div class="col-xs-6 col-sm-4">-->
<!--							<div class="form-group">-->
<!--								<div class=" col-sm-11">-->
<!--									<button class="btn btn-warning" >返回上一页</button>-->
<!--								</div>-->
<!--							</div>-->
<!--						</div>-->
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	function submitForm() {
		// let data = {};
		// let formData = $('#newsForm').serializeArray();
		// $.each(formData, function() {
		// 	data[this.name] = this.value;
		// });
		let data = new FormData($("#newsForm")[0]);
		Vue.http.post('addNews',data,{emulateJSON:true})
				.then((res) => {
					if (res.data.code==200){
						parent.layer.msg(res.data.message);
						//	刷新父页面
						parent.getNews(1);
						closeLayer();
					}else {
						parent.layer.msg(res.data.message);
					}
				},(error)=>{
					console.log(error);
				});
	}

	function closeLayer() {
		parent.layer.close(parent.layer.getFrameIndex(window.name));
	}
</script>
</html>
